<template>
	<view class="content">
		<mescroll-uni ref="mescrollRef" @init="mescrollInit" @up="upCallback" :up="upOption" :down="{use: false}">
			<view class="section-1">
				<view class="section-body">
					<view class="tab">
						<view @click="setCurIdx(idx, item.name)"
							:class="`item ${curName === item.name ? 'item__active' : ''} ${curIdx + 1 === idx ? 'item__active_next' : ''}`"
							v-for="(item, idx) in tabList" :key="item.id">
							<view class="label">
								{{item.name}}{{`(${item.quantity})`}}
							</view>
							<view class="shape">
								<view class="shape-body"></view>
							</view>
							<view class="shape shape-mirrow">
								<view class="shape-body"></view>
							</view>
						</view>
					</view>
					<view class="form">
						<view class="form-item">
							<view class="label">搜索</view>
							<view class="shape"></view>
							<view class="input">
								<u--input placeholderClass="input-placeholder" class="input-body" placeholder="停电设备名称"v-model="form.name"></u--input>
							</view>
						</view>
						<view class="actions">
							<view class="action" @click="handleResetForm()">
								<text>重</text>
								<text>置</text>
							</view>
							<view class="action search" @click="handleSearch()">
								<text>查</text>
								<text>询</text>
							</view>
						</view>
					</view>
					<view class="list" v-if="list.length > 0">
						<view class="item" v-for="(item, index) in list" :key="item.id">
							<view class="parent" @click="go(item)">
								<!-- <view class="action">
									<view class="iconfont icon-xiala"></view>
								</view> -->
								<view class="name">
									{{index + 1}}.{{item.sb_name}}
									<view class="buttonTime">
										<text>开始时间:{{item.start_date?item.start_date.substring(0, 10): '--'}}</text><text>结束时间:{{item.end_date?item.end_date.substring(0, 10): '--'}}</text>
										<view class="tdDay">停电天数:{{item.td_day}}天</view>
									</view>
								</view>
								<view :class="item.is_high_risk==='是' ? 'right':''">
									{{item.is_high_risk==='是'? '五级风险':''}}
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</mescroll-uni>
	</view>
</template>

<script>
	import {
		ListOfOutAgeDetails,
		ProjectPowerRiskTotal
	} from '@/api/outage.js';
	import {
		mapGetters,
		mapActions
	} from 'vuex';
	export default {
		data() {
			return {
				form: {
					name: "",
				},
				list: [],
				mescroll: null, // mescroll实例对象 (此行可删,mixins已默认)
				upOption: {
					textNoMore: '-- 没有更多了 --'
				},
				pageSize: 20,
				curIdx: 0,
				curName: '执行中',
				curTab: {
					id: 1,
					name: '执行中'
				},
				tabList: [{
						name: '执行中',
						id: 1,
						quantity: 0
					},
					{
						name: '已完成',
						id: 2,
						quantity: 0
					},
					{
						name: '待执行',
						id: 3,
						quantity: 0
					},
				],
			};
		},
		computed: {
			...mapGetters({
				curProject: 'system/getCurProject',
			})
		},
		methods: {
			go(params) {
				uni.navigateTo({
					url: '/pages/work/manager/construction/safety/outage/info/index?params=' + JSON.stringify(params)
				})
			},
			setCurIdx(idx, name) {
				this.curIdx = idx;
				this.curName = name;
				this.expandList = [];
				this.mescroll.resetUpScroll();
				this.mescroll.scrollTo(0, 0);
				// this.fetchInfo(idx + 1)
			},
			mescrollInit(mescroll) {
				this.mescroll = mescroll;
			},
			handleResetForm() {
				for (let key in this.form) {
					this.form[key] = "";
				}
				this.mescroll.resetUpScroll();
				this.mescroll.scrollTo(0, 0);
			},
			handleSearch() {
				this.mescroll.resetUpScroll();
				this.mescroll.scrollTo(0, 0);
			},
			/*上拉加载的回调*/
			async upCallback(page) {
				let obj = {
					...this.form
				}
				// if (this.curBoard !== 0) {
				// 	obj.process_status = this.curBoard
				// }
				const {
					data
				} = await ListOfOutAgeDetails({
					...obj,
					id: this.curProject.id,
					// id:'78a7ba6a-55ca-49d3-9286-0f49d9e66ee4',
					// page: page.num,
					process_status:this.curIdx+1,
					pageSize: this.pageSize,
				});
				if (data.code === 1 || data.code === 200) {
					// 接口返回的当前页数据列表 (数组)
					let curPageData = data.data;
					// 接口返回的当前页数据长度 (如列表有26个数据,当前页返回8个,则curPageLen=8)
					let curPageLen = curPageData.length;
					// 接口返回的总页数 (如列表有26个数据,每页10条,共3页; 则totalPage=3)
					let totalPage = data.data.last_page;
					this.list = data.data
					//设置列表数据
					// if(page.num == 1) this.list = []; //如果是第一页需手动置空列表
					// this.list = this.list.concat(curPageData); //追加新数据
					// 请求成功,隐藏加载状态
					this.mescroll.endByPage(curPageLen, totalPage);
					setTimeout(() => {
						this.mescroll.endSuccess(curPageLen);
					}, 20);
				} else {
					//  请求失败,隐藏加载状态
					this.mescroll.endErr()
				}
				const  quantity  = await ProjectPowerRiskTotal({
					project_id: this.curProject.id,
					// project_id:'78a7ba6a-55ca-49d3-9286-0f49d9e66ee4',
				});
				console.log(quantity)
				//添加每项作业票的数量
				this.tabList.forEach(item => {
					if (item.name === '执行中') {
						item.quantity = quantity.data.data.power_executing
					} else if (item.name === '已完成') {
						item.quantity = quantity.data.data.power_finsh
					} else {
						item.quantity = quantity.data.data.power_wait
					}
				})
			},
		},
		onShow() {
			this.upCallback()
		},
		onNavigationBarButtonTap(res) {
			uni.navigateTo({
				url: '/pages/work/manager/construction/safety/outage/add/index'
			})
		}
	}
</script>

<style lang="scss" scoped>
	.custom-empty {
		position: static;
	}

	.content {
		background-color: #fff;
	}

	.section-1 {
		width: 100%;
		background-color: #2e5efe;

		.section-body {
			background-color: #fff;
			border-top-left-radius: 50rpx;
			border-top-right-radius: 50rpx;

			.tab {
				width: 100%;
				height: 80rpx;
				@include clear();
				background-color: #1534ce;

				.item {
					width: 33.33%;
					float: left;
					height: 80rpx;
					background-color: #1534ce;
					position: relative;

					.label {
						height: 80rpx;
						line-height: 80rpx;
						position: relative;
						z-index: 10;
						box-sizing: border-box;
						text-align: center;
						width: 100%;
						font-size: 26rpx;
						font-weight: normal;
						font-stretch: normal;
						letter-spacing: 0rpx;
						color: #fefefe;
					}

					.shape {
						z-index: 1;
						width: 50rpx;
						height: 50rpx;
						position: absolute;
						bottom: 0;
						left: -50rpx;
						background: #000;
						display: none;
						background-color: #fff;
						overflow: hidden;

						.shape-body {
							width: 50rpx;
							height: 50rpx;
							background-color: #1534ce;
							border-bottom-right-radius: 40rpx;
						}
					}

					.shape-mirrow {
						z-index: 1;
						left: 0;
						display: none;

						.shape-body {
							border-bottom-right-radius: 0rpx;
							border-bottom-left-radius: 40rpx;
						}
					}
				}

				.item__active {
					border-top-left-radius: 40rpx;
					border-top-right-radius: 40rpx;
					background-color: #fff;

					.label {
						color: #46464a;
					}

					.shape {
						display: block;
					}

					.shape-mirrow {
						display: none;
					}
				}

				.item__active_next {
					border-bottom-right-radius: 50rpx;

					.shape {
						display: none;
					}

					.shape-mirrow {
						display: block;
					}
				}

			}

			.list {
				width: 670rpx;
				box-sizing: border-box;
				margin-left: 40rpx;
				.item {
					width: 100%;
					border-bottom: solid 2rpx #f2f2f0;
					.parent {
						width: 100%;
						height: 130rpx;
						// border-top: solid 2rpx #f2f2f0;
						position: relative;
						.name {
							width: 620rpx;
							// height: 82rpx;
							font-size: 26rpx;
							font-weight: normal;
							font-stretch: normal;
							letter-spacing: 2rpx;
							color: #3b3c40;
							text-overflow: ellipsis;
							overflow: hidden;
							white-space: nowrap;
							// padding-left: 30rpx;
							position: absolute;
							top: 30rpx;
							.buttonTime{
								font-size: 25rpx;
								color: #7c7f83;
								text{
									margin-right: 20rpx;
								}
							}
						}

						.right{
							background-color: #ce0006;
							position: absolute;
							top: 0;
							right: 0;
							height: 120rpx;
							width: 40rpx;
							font-size: 20rpx;
							text-align: center;
							border-bottom-left-radius: 20rpx;
							border-bottom-right-radius: 20rpx;
							color: #fff;
						}
						.count {
							float: right;
							min-width: 46rpx;
							height: 46rpx;
							margin-top: 18rpx;
							border-radius: 28rpx;
							line-height: 46rpx;
							text-align: center;
							font-size: 26rpx;
							font-weight: bold;
							color: #395cf5;
							background: #ffde00;
							margin-right: 40rpx;

							text {
								font-size: 16rpx;
							}
						}

						.action {
							float: left;
							width: 32rpx;
							margin-right: 18rpx;
							height: 100%;
							line-height: 82rpx;
							text-align: center;
							color: #3b3c40;

							.iconfont {
								font-size: 32rpx;
								transition: 0.2s ease;
							}

						}
					}

					.child {
						width: 750rpx;
						margin-left: - 40rpx;
						background: #f2f2fa;

						.child-item {
							width: 620rpx;
							margin-left: 90rpx;
							border-bottom: 2rpx solid #e3e8f5;
							position: relative;

							&:last-child {
								border-bottom: none;
							}

							.top {
								width: 100%;
								overflow: hidden;
								height: 70rpx;

								.name {
									float: left;
									width: 620rpx;
									height: 70rpx;
									line-height: 70rpx;
									color: #3b3c40;
									font-size: 26rpx;
									text-overflow: ellipsis;
									overflow: hidden;
									white-space: nowrap;
								}

								.action {
									position: absolute;
									width: 40rpx;
									height: 70rpx;
									line-height: 70rpx;
									top: 20rpx;
									right: 0;
									text-align: right;
									color: #7f98ae;

									.iconfont {
										font-size: 26rpx;
									}
								}
							}


						}

						.info {
							height: 40rpx;
							overflow: hidden;

							view {
								height: 24rpx;
								line-height: 24rpx;
								float: left;
								margin-right: 20rpx;
								font-size: 18rpx;
								color: #7f98ae;
							}
						}
					}
				}
			}

			.item__expand {
				.parent {
					.action {
						.iconfont {
							transform: rotate(-180deg);
						}
					}
				}

				.child {
					box-shadow: 0rpx 10rpx 20rpx 0rpx rgba(0, 0, 0, 0.05) inset;
				}
			}
		}

		.actions {
			width: 100%;
			height: 50rpx;
			margin-top: 29rpx;
			padding-bottom: 40rpx;
			display: flex;
			justify-content: space-between;

			.action {
				width: 288rpx;
				height: 48rpx;
				background-color: #395cf5;
				border-radius: 20rpx;
				text-align: center;
				line-height: 48rpx;
				font-size: 26rpx;
				font-weight: normal;
				font-stretch: normal;
				line-height: 48rpx;
				color: #ffffff;

				text {
					&:first-child {
						margin-right: 20rpx;
					}
				}
			}

			.search {
				background-color: #1534ce;
			}
		}

		.form {
			width: 100%;
			padding: 0 75rpx;
			padding-top: 40rpx;
			box-sizing: border-box;
             border-bottom: 2rpx solid #f2f2f0;
			.form-item {
				width: 600rpx;
				height: 48rpx;
				border-radius: 20rpx;
				border: solid 2rpx #1534ce;
				margin: 0 auto;
				margin-bottom: 34rpx;
				@include clear();

				.label {
					float: left;
					width: 134rpx;
					height: 48rpx;
					text-align: center;
					line-height: 44rpx;
					font-size: 26rpx;
					font-weight: normal;
					font-stretch: normal;
					letter-spacing: 0rpx;
					color: #1534ce;
				}

				.shape {
					width: 3rpx;
					height: 32rpx;
					background-color: #7f98ae;
					float: left;
					margin-top: 8rpx;
				}

				.input {
					float: left;
					width: calc(100% - 134rpx - 3rpx);

					.input-body {
						box-sizing: border-box;
						width: 100%;
						height: 44rpx;
						padding: 0 !important;
						border: none;
						padding-left: 30rpx !important;
						padding-right: 30rpx !important;
						font-size: 26rpx;
						font-weight: normal;
						font-stretch: normal;
						letter-spacing: 0rpx;
						color: rgba(0, 0, 0, 0.7);
					}

					.input-placeholder {
						font-size: 26rpx;
						font-weight: normal;
						font-stretch: normal;
						letter-spacing: 0rpx;
						color: rgba(0, 0, 0, 0.5);
					}
				}
			}
		}
	}
</style>
